package router

import (
	"dog-blog/app/post/apis/article"
	"dog-blog/app/post/apis/comment"
	"dog-blog/app/post/apis/custom"
	"dog-blog/base/storage"
	"dog-blog/sdk"

	"github.com/gin-gonic/gin"
)

// Init init
func InitRouter() {
	router := sdk.Runtime.GetEngine().(*gin.Engine)
	router.Use(gin.Recovery())
	router.Static("/res", storage.GetBasic().Posts+"res")

	apiV1 := router.Group("api/v1")
	initGlobalAPIRouter(apiV1)
	initArticleAPIRouter(apiV1)
	initCommentRouter(apiV1)
}

func initGlobalAPIRouter(rg *gin.RouterGroup) {
	custom := &custom.Custom{}
	r := rg.Group("/global")
	{
		r.GET("/retrieval", custom.Retrieval)
		r.GET("/captcha", custom.GenerateCaptcha)
		r.GET("/git/:option", custom.GitOption)
	}
}

func initArticleAPIRouter(rg *gin.RouterGroup) {
	article := &article.Article{}
	r := rg.Group("/article")
	{
		r.GET("/", article.GetArticles)
		r.GET("/:id", article.GetArticle)
		// c.GET("/recommend", controler.Recommend)
	}
}

func initCommentRouter(rg *gin.RouterGroup) {
	comment := &comment.Comment{}
	r := rg.Group("/comment")
	{
		r.POST("/", comment.CreateComment)
		r.GET("/", comment.GetAllComment)
		r.GET("/:id", comment.GetComment)
		r.PUT("/:id", comment.UpdateComment)
		r.DELETE("/:id", comment.DeleteComment)
	}
}
